package com.taskflow.controller;

import com.taskflow.common.PageResult;
import com.taskflow.common.Result;
import com.taskflow.dto.LogQueryDTO;
import com.taskflow.entity.DownloadLog;
import com.taskflow.service.DownloadLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 下载日志Controller
 */
@RestController
@RequestMapping("/log")
@CrossOrigin
public class DownloadLogController {

    @Autowired
    private DownloadLogService logService;

    /**
     * 获取日志详情
     */
    @GetMapping("/{id}")
    public Result<DownloadLog> getLog(@PathVariable Long id) {
        try {
            DownloadLog log = logService.getLogById(id);
            if (log == null) {
                return Result.error("日志不存在");
            }
            return Result.success(log);
        } catch (Exception e) {
            return Result.error("获取日志失败: " + e.getMessage());
        }
    }

    /**
     * 获取日志列表
     */
    @GetMapping("/list")
    public Result<PageResult<DownloadLog>> getLogList(LogQueryDTO query) {
        try {
            PageResult<DownloadLog> result = logService.getLogList(query);
            return Result.success(result);
        } catch (Exception e) {
            return Result.error("获取日志列表失败: " + e.getMessage());
        }
    }
}

